package cn.ffcs.uec.staff.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cn.ffcs.uec.staff.dao.UecPunishDao;
import cn.ffcs.uec.staff.model.UecPunish;
import cn.ffcs.uom.common.constants.BaseUnitConstants;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("uecPunishDao")
@Transactional
public class UecPunishDaoImpl extends BaseDaoImpl implements UecPunishDao {

	@Override
	public PageInfo queryPageInfoByUecPunish(UecPunish uecPunish, int current,
			int pageSize) {
		if (null != uecPunish) {
			StringBuilder sb = new StringBuilder(
					" SELECT * FROM UEC_PUNISH T WHERE T.STATUS_CD = ? ");
			List<Object> params = new ArrayList<Object>();
			params.add(BaseUnitConstants.ENTT_STATE_ACTIVE);
			
			//判断这个对象是外包人员的数据还是合同制的数据
			if (BaseUnitConstants.NM_OUT_STAFF_TYPE.equals(uecPunish.getNmStaffType())) {
				sb.append(" AND T.NM_STAFF_TYPE = ? ");
				params.add(BaseUnitConstants.NM_OUT_STAFF_TYPE);
			}

			if (!StrUtil.isNullOrEmpty(uecPunish.getPkPsndoc())) {//判断数据是否是集团的
				sb.append(" AND T.PK_PSNDOC = ? ");
				params.add(uecPunish.getPkPsndoc());
			} else if (null != uecPunish.getStaffId()) {
				sb.append(" AND T.STAFF_ID = ? ");
				params.add(uecPunish.getStaffId());
			}
			return this.jdbcFindPageInfo(sb.toString(), params, current,
					pageSize, UecPunish.class);
		}
		return null;
	}

	@Override
	public UecPunish findUecPunishById(UecPunish uecPunish) {
		if (null != uecPunish) {
			StringBuilder sb = new StringBuilder(
					" SELECT * FROM UEC_PUNISH T WHERE 1=1 ");
			List<Object> params = new ArrayList<Object>();
			if (!StrUtil.isNullOrEmpty(uecPunish.getPunishId())) {
				sb.append(" AND T.PUNISH_ID = ? ");
				params.add(uecPunish.getPunishId());
			}
			List<UecPunish> uecPunishs = this.jdbcFindList(sb.toString(), params, UecPunish.class);
			if (null != uecPunishs && uecPunishs.size() > 0) {
				return uecPunishs.get(0);
			}else {
				return null;
			}
		}
		return uecPunish;
	}

	@Override
	public PageInfo queryPageInfoByUecPunishOnApproval(UecPunish uecPunish,
			int current, int pageSize) {
		if (null != uecPunish) {
			StringBuilder sb = new StringBuilder(
					" SELECT * FROM UEC_PUNISH T WHERE T.STATUS_CD = ? ");
			List<Object> params = new ArrayList<Object>();
			params.add(BaseUnitConstants.ENTT_STATE_PROCESS);
			
			//判断这个对象是外包人员的数据还是合同制的数据
			if (BaseUnitConstants.NM_OUT_STAFF_TYPE.equals(uecPunish.getNmStaffType())) {
				sb.append(" AND T.NM_STAFF_TYPE = ? ");
				params.add(BaseUnitConstants.NM_OUT_STAFF_TYPE);
			}

			if (!StrUtil.isNullOrEmpty(uecPunish.getPkPsndoc())) {//判断数据是否是集团的
				sb.append(" AND T.PK_PSNDOC = ? ");
				params.add(uecPunish.getPkPsndoc());
			} else if (null != uecPunish.getStaffId()) {
				sb.append(" AND T.STAFF_ID = ? ");
				params.add(uecPunish.getStaffId());
			}
			return this.jdbcFindPageInfo(sb.toString(), params, current,
					pageSize, UecPunish.class);
		}
		return null;
	}

}
